package com.briup.server.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.common.response.Result;
import com.briup.server.domain.dto.RentalAppointmentDTO;
import com.briup.server.domain.dto.RentalApprovalDTO;
import com.briup.server.domain.dto.RentalQueryDTO;
import com.briup.server.domain.vo.RentalInfoVO;
import com.briup.server.service.RentalInfosService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "实验室预约管理接口")
@RestController
@RequestMapping("/rental")
@RequiredArgsConstructor
public class RentalAppointmentController {

    private final RentalInfosService service;

    @Operation(summary = "预约实验室")
    @PostMapping("/appointment")
    public Result<?> appointment(
            @RequestBody @Valid RentalAppointmentDTO dto) {
        service.appointment(dto);
        return Result.success();
    }

    @Operation(summary = "查询预约信息")
    @GetMapping("/query")
    public Result<Page<RentalInfoVO>> queryRentalInfos(RentalQueryDTO dto) {
        Page<RentalInfoVO> page = service.queryRentalInfos(dto);
        return Result.success(page)
                .apply("查询预约信息成功");
    }

    @Operation(summary = "审核预约信息")
    @PostMapping("/approval")
    public Result<?> approval(
            @RequestBody @Valid RentalApprovalDTO dto) {
        service.approval(dto);
        return Result.success();
    }
}
